

on clicked theObject
	set nomeBotao to name of theObject
	
	my ozalide("ozalide1", nomeBotao, "ozalide1")
	my ozalide("ozalide2", nomeBotao, "ozalide2")
	my ozalide("ozalide3", nomeBotao, "ozalide3")
	my ozalide("ozalide4", nomeBotao, "ozalide4")
end clicked

on action theObject
	
end action





on ozalide(textField, nomeBotao, nomeField)
	
	set dataOzalide to get contents of text field textField of tab view item "prepress" of tab view "tabObras" of window "Prepress Ver Obras"
	set dataOzalideBackup to get contents of text field textField of tab view item "prepress" of tab view "tabObras" of window "Prepress Ver Obras"
	
	if dataOzalide ≠ "" then
		set AppleScript's text item delimiters to "-"
		set ano to dataOzalide's text item 1
		set mes to dataOzalide's text item 2
		set dia to dataOzalide's text item 3 as integer
		
		
		
		set lenghtOfAno to length of ano
		
		
		if lenghtOfAno ≠ 4 or mes ≥ 13 or dia ≥ 32 then
			display alert "A data está mal escrita. 
Utilize o formato '2008-1-10'"
			
			set contents of text field textField of tab view item "prepress" of tab view "tabObras" of window "Prepress Ver Obras" to dataOzalideBackup
		else
			
			set nObra to get contents of text field "nObra" of window "Prepress Ver Obras"
			set dataOzalide to get contents of text field textField of tab view item "prepress" of tab view "tabObras" of window "Prepress Ver Obras"
			
			tell user defaults
				set theDatabaseFinal to contents of default entry "theDatabaseFinal"
			end tell
			
			set theDatabase to space & theDatabaseFinal & space
			set theDatabase to "sqlite3" & theDatabase & quote
			set changes to "update auxiliar1 set " & nomeField & " = '" & dataOzalide & "' where nObra='" & nObra & "'; "
			do shell script theDatabase & changes & quote
			
		end if
		
	end if
	set AppleScript's text item delimiters to ""
end ozalide


